package com.example.s06;

import com.example.s06.entity.Apple;
import com.example.s06.entity.Customer;
import com.example.s06.entity.Pear;
import com.example.s06.entity.User;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ImportResource;

//@ImportResource("classpath:beans/user.xml")//使用xml文件方式注入必须加入该语句
@SpringBootApplication
@Data
public class S06Application {


    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(S06Application.class, args);
//        String[] beanDefinitionNames = context.getBeanDefinitionNames();
//        for(String name:beanDefinitionNames){
//            System.out.println(name);
//        }
//        User user = context.getBean("user",User.class);
//        User user1 = context.getBean("user1",User.class);
//        User user2 = context.getBean("user2",User.class);

//        Customer customer=context.getBean("customer",Customer.class);

//        System.out.println(user);
//        System.out.println(user1);
//        System.out.println(user2);

//        System.out.println(customer);


        Apple apple1 = context.getBean(Apple.class);
        Apple apple2 = context.getBean(Apple.class);
        apple1.setName("烟台苹果");
        apple2.setName("山东苹果");
        System.out.println(apple1);
        System.out.println(apple2);
//        只会输出apple2，因为Apple是单实例模式，apple1和apple2是相同的对象

        Pear pear1 = context.getBean(Pear.class);
        Pear pear2 = context.getBean(Pear.class);
        pear1.setName("烟台梨");
        pear2.setName("山东梨");
        System.out.println(pear1);
        System.out.println(pear2);

    }

}
